package com.dorm.cj.design.demo;

import com.dorm.cj.design.JsonMapper;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

public class Zoo extends Base {

    public static void main(String[] args) throws IOException {
        Zoo zoo = new Zoo();
        zoo.set("hello", "value1");
        zoo.setName("动物园");
        Dog dog = new Dog();
        dog.setDogName("xiaoheigou");
        zoo.setDog(dog);

        ObjectMapper mapper = new ObjectMapper();
        String dogjsonstr = mapper.writeValueAsString(zoo);

        System.out.println(dogjsonstr);
//        Zoo zoo0 = mapper.readValue(dogjsonstr, Zoo.class);
//        System.out.println(zoo0.toString());
        System.out.println("=========================");
        String toJson = JsonMapper.JSON_MAPPER_NON_EMPTY.toJson(zoo);
        System.out.println(toJson);
        Zoo zoo1 = JsonMapper.JSON_MAPPER_NON_EMPTY.fromJson(toJson, Zoo.class);
        System.out.println(zoo1.toString());
    }

    private String name;

    private Dog dog;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @JsonMerge
    public Dog getDog() {
        return dog;
    }

    public void setDog(Dog dog) {
        this.dog = dog;
    }

    @Override
    public java.lang.String toString() {
        return "Zoo{" +
                "name=" + name +
                '}' + extra;
    }
}
